import React, { useReducer } from "react";

function ReducerDemo() {
    const [count, dispatch] = useReducer((state, action) => {
        switch (action) {
            case "add":
                return state + 1
            case "sub":
                return state - 1
            default:
                return state
        }
    }, 0); // 这个是默认值

    return (
        <div>
            <h2>你现在的分数是{count}分</h2>
            <button onClick={() => dispatch('add')}>Increment</button>
            <button style={{ marginLeft: `15px` }} onClick={() => dispatch('sub')} type="">Decrement</button>
        </div>
    )
}

export default ReducerDemo